package com.ucode.hrm.controller;

import com.ucode.hrm.service.HrmEmployeeCompensationService;
import com.ucode.model.hrm.HrmEmployeeCompensation;
import com.ucode.model.hrm.convert.HrmEmployeeCompensationConvert;
import com.ucode.model.hrm.form.HrmEmployeeCompensationForm;
import com.ucode.tool.base.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Tag(name = "管理后台 - 人力资源系统 - 员工薪酬")
@RestController
@RequestMapping("/hrm/employee-compensation")
@Validated
public class HrmEmployeeCompensationController {

    @Resource
    private HrmEmployeeCompensationService employeeCompensationService;

    @GetMapping("/getById/{id}")
    @Parameter(description="主键ID",name = "id", required = true,in = ParameterIn.PATH,example = "1024")
    @Operation(summary = "主键获得信息")
    @PreAuthorize("@usfs.hasPermission('hrm:employee-compensation:query')")
    public ResponseResult<HrmEmployeeCompensation> getById(@PathVariable(name="id",required=true) Long id){
        HrmEmployeeCompensation bean = employeeCompensationService.selectByPrimaryKey(id);
        return ResponseResult.success(bean);
    }

    @PostMapping("/save")
    @Operation(summary = "保存")
    @PreAuthorize("@usfs.hasPermission('hrm:employee-compensation:save')")
    public ResponseResult<Long> save(@Valid @RequestBody HrmEmployeeCompensationForm form) {
        HrmEmployeeCompensation bean = HrmEmployeeCompensationConvert.INSTANCE.convert(form);
        employeeCompensationService.save(bean);
        return ResponseResult.success(bean.getId());
    }

}
